clear all

cd "/Users/sambuehl/Dropbox/ForTheyKnowNot/ForTheyKnowNot/REPLICATION PACKAGE/"
 
 
set more off

use "data/data.dta", replace

******* Data householding 
if 1 {
	su iq
	local mean = r(mean)
	local sd = r(sd)
	capture gen iqNorm = 15 * (iq - `mean')/`sd' + 100

	
	egen iqR = rank(iq) 
	count 
	local numSub = r(N)
	replace iqR = iqR / `numSub'
	
	egen iqRankUninc = rank(iq) if session <= 10 
	count if session <= 10 
	local numUninc = r(N)
	replace iqRankUninc = iqRankUninc / `numUninc'
	
	egen iqRankInc = rank(iq) if session > 10 & session <= 17
	count if session > 10 & session <= 17
	local numInc = r(N)
	replace iqRankInc = iqRankInc / `numInc'
	

	gen resPrice = (resPrice1 + resPrice2 + resPrice3 + resPrice4) / 4

	forvalues i = 1 / 4 {
		egen wtaRank`i' = rank(resPrice`i')
		replace wtaRank`i' = wtaRank`i' / _N
	}

	egen wtaRankMean = rank(resPrice)
	replace wtaRankMean = wtaRankMean / _N	

	bysort id: egen medTpic = median(tpicQ) if explicit == 0
	su medTpic, d
	gen shortTime = medTpic < r(p25)
	gen medTime = medTpic < r(p50)	
	
	replace abischnitt = . if abischnitt > 4
	replace abimath = . if abimath > 15
	replace abideutsch = . if abideutsch > 15

	drop lm*wta*
	
	gen emailGiven = email ~= ""
	
	// Risk aversion measures
	capture drop ceMean
	gen ceMean = ce1 + ce2 + ce3 + ce4 + ce5 + ce6 + ce7 + ce8 + ce9
	sort ceMean
	egen ceRank_i = rank(ceMean) if tagId == 1
	bysort id: egen ceRank = mean(ceRank_i)
	su ceRank
	replace ceRank = ceRank / r(max)
	drop ceRank_i
	count if tagId == 1
	local N = r(N)
	capture drop riskAversionIndex
	gen riskAversionIndex_i = 1 - (ceRank / `N')
	bysort id: egen riskAversionIndex = max(riskAversionIndex_i)
	capture drop ceOdd ceEven
	gen ceOdd = ce1 + ce3 + ce5 + ce7 + ce9
	gen ceEven = ce2 + ce4 + ce6 + ce8
	
	gen resPriceOdd = resPrice1 + resPrice3
	gen resPriceEven = resPrice2 + resPrice4
	

	capture drop iqEven iqOdd iqPred*
	gen iqEven = iq2+iq4+iq6+iq8+iq10+iq12+iq14+iq16+iq18+iq20+iq22+iq24+iq26+iq28+iq30+iq32+iq34+iq36
	gen iqOdd = iq1+iq3+iq5+iq7+iq9+iq11+iq13+iq15+iq17+iq19+iq21+iq23+iq25+iq27+iq29+iq31+iq33+iq35
	
	
	
	su incentive
	if r(min) == -1 {
		replace incentive = incentive + 1
	}


	foreach var in monthlyexpenses ownearnings allowance parentwealth {
		capture gen log`var' = log(`var')
	}
	
	capture drop moneyPCA
	pca logmonthlyexpenses logownearnings logallowance logparentwealth
	predict moneyPCA, sc
	// note: stata centers and scales the PCA inputs automatically
	
	capture drop minLogTiq
	gen minLogTiq = min(logTiq1, logTiq2, logTiq3, logTiq4, logTiq5, logTiq6)
		
	gen sessionTime = .
	replace sessionTime = 1 if session == 1
	replace sessionTime = 1 if session == 2
	replace sessionTime = 2 if session == 3
	replace sessionTime = 3 if session == 4
	replace sessionTime = 1 if session == 5
	replace sessionTime = 2 if session == 6
	replace sessionTime = 1 if session == 7
	replace sessionTime = 2 if session == 8
	replace sessionTime = 1 if session == 9
	replace sessionTime = 2 if session == 10
	replace sessionTime = 2 if session == 11	
	replace sessionTime = 1 if session == 12
	replace sessionTime = 2 if session == 13
	replace sessionTime = 1 if session == 14
	replace sessionTime = 2 if session == 15
	replace sessionTime = 1 if session == 16
	replace sessionTime = 2 if session == 17
	replace sessionTime = 1 if session == 18
	replace sessionTime = 2 if session == 19
	
	gen sessionWeekday = . // 1 = Monday, 2 = Tuesday, ...
	replace sessionWeekday = 4 if session == 1
	replace sessionWeekday = 3 if session == 2
	replace sessionWeekday = 3 if session == 3
	replace sessionWeekday = 3 if session == 4
	replace sessionWeekday = 3 if session == 5
	replace sessionWeekday = 3 if session == 6
	replace sessionWeekday = 4 if session == 7
	replace sessionWeekday = 4 if session == 8
	replace sessionWeekday = 5 if session == 9
	replace sessionWeekday = 5 if session == 10
	replace sessionWeekday = 5 if session == 11
	replace sessionWeekday = 1 if session == 12
	replace sessionWeekday = 1 if session == 13
	replace sessionWeekday = 1 if session == 14
	replace sessionWeekday = 1 if session == 15
	replace sessionWeekday = 2 if session == 16
	replace sessionWeekday = 2 if session == 17
	replace sessionWeekday = 1 if session == 18
	replace sessionWeekday = 1 if session == 19
	
	gen friday = sessionWeekday == 5
	
	
	gen riskPremium = 0
	forvalues i = 1 / 9 {
		gen riskPremium`i' = ce`i' - ceRiskNeut`i'
		replace riskPremium = riskPremium + riskPremium`i'/9
	}
	gen riskAverse = riskPremium < 0
	
	if 0 {
		gen thresCost = .
		replace thresCost = 7.28 if cost == 1
		replace thresCost = 12.64 if cost == 2
		replace thresCost = 27.41 if cost == 3
	}
	else {
		gen thresCost = cost
	}
		
	su thresCost 
	local minThresCost = r(min)
	replace thresCost = thresCost / `minThresCost'

	replace cost = 0 if explicit == 1
	replace thresCost = 0 if explicit == 1
	
	gen inc_thresCost = incentive * thresCost
	gen inc_explGood = incentive * explicitGood
	gen inc_explBad = incentive * explicitBad
	gen inc_explicit = incentive * explicit
	
	gen inc_wtaRankMean = incentive * wtaRankMean
	gen thresCost_wtaRankMean = thresCost * wtaRankMean
	gen thresCost_inc_wtaRankMean = thresCost * inc_wtaRankMean
	
	gen inc_iqRankUninc = incentive * iqRankUninc
	gen thresCost_iqRankUninc = thresCost * iqRankUninc
	gen thresCost_inc_iqRankUninc = thresCost * inc_iqRankUninc

	gen inc_iqRankInc = incentive * iqRankInc
	gen thresCost_iqRankInc = thresCost * iqRankInc
	gen thresCost_inc_iqRankInc = thresCost * inc_iqRankInc	
	
	drop incentives 	// this is some variable that was used in the javascript code of the survey
	
	
	
	capture drop responsiveness*
	gen responsivenessPos_i = (plik - 0.5) / (bayesPost - 0.5) if explicit == 1 & bayesPost > 0.5
	bysort id: egen responsivenessPos = mean(responsivenessPos_i)
	gen responsivenessNeg_i = (plik - 0.5) / (bayesPost - 0.5) if explicit == 1 & bayesPost < 0.5
	bysort id: egen responsivenessNeg = mean(responsivenessNeg_i)
	
	gen responsiveness_i = .
	replace responsiveness_i = responsivenessPos_i if bayesPost > 0.5 
	replace responsiveness_i = responsivenessNeg_i if bayesPost < 0.5 
	bysort id: egen responsiveness = mean(responsiveness_i)


	
	
	egen abimathRank = rank(abimath)  
	count 
	local num = r(N)
	replace abimathRank = abimathRank / `num'
	
	egen abideutschRank = rank(abideutsch)  
	count 
	local num = r(N)
	replace abideutschRank = abideutschRank / `num'
	

	egen abiRank = rank(abischnitt)  
	count 
	local num = r(N)
	replace abiRank = abiRank / `num'
	
	gen STEM = major == 1 | major == 5
	
	bysort id: egen minTpic = min(tpicQ) if explicit == 0

	
}

******* Supply curves
if 1 {
	// Experimental variation in information acquisition costs	
	if 1 {	
		capture: postclose supplyCurves
		postfile supplyCurves mean sd incentive cost using "data/supplyCurves.dta", replace
		
		capture drop weightSupplyCurves
		gen weightSupplyCurves = .

		su treatment
		local numTreatments = r(max)
		forvalues t = 1 / `numTreatments' {
			su state if treatment == `t' & session >= 5
			replace weightSupplyCurves = 1 / r(mean)			if state == 1 & treatment == `t'
			replace weightSupplyCurves = 1 / (1 - r(mean)) 		if state == 0 & treatment == `t'
		}
		
		
		reg bet [aw = weightSupplyCurves] if incentive == 0 & cost == 1 & session >= 5
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (0)
		reg bet [aw = weightSupplyCurves] if incentive == 1  & cost == 1 & session >= 5 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (0)
		reg bet [aw = weightSupplyCurves] if incentive == 2  & cost == 1 & session >= 5 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (0)
		
		reg bet [aw = weight] if incentive == 0 & cost == 2 
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (1)
		reg bet [aw = weight] if incentive == 1  & cost == 2 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (1)
		reg bet [aw = weight] if incentive == 2  & cost == 2 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (1)
		reg bet [aw = weight] if incentive == 0 & cost == 3 
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (2)
		reg bet [aw = weight] if incentive == 1  & cost == 3 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (2)
		reg bet [aw = weight] if incentive == 2  & cost == 3 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (2)

		
		gen costMinus = cost
		reg costMinus [aw = weightSupplyCurves] if incentive == 0 & bet == 1 & explicit == 0
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (3)
		reg costMinus [aw = weight] if incentive == 1 & bet == 1 & explicit == 0 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (3)
		reg costMinus [aw = weight] if incentive == 2 & bet == 1 & explicit == 0 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (3)
		
		postclose supplyCurves
		
		
		preserve
			clear
			use "data/supplyCurves.dta"
			gen upper = mean + 1.96*sd
			gen lower = mean - 1.96*sd
			
			tw 	(line mean incentive if cost == 0, lpattern(shortdash) lcolor(blue)		lwidth(0.55)) ///
				(line mean incentive if cost == 1, lpattern(longdash) lcolor(dkgreen)	lwidth(0.55)) ///
				(line mean incentive if cost == 2, lpattern(solid)  lcolor(red)	lwidth(0.55)) /// 
				(line mean incentive if cost == 3, lpattern(solid)		lwidth(1.35) lcolor(black) yaxis(2)) /// 
				(rcap upper lower incentive if cost == 0, lcolor(blue)) ///
				(rcap upper lower incentive if cost == 1, lcolor(dkgreen)) ///
				(rcap upper lower incentive if cost == 2, lcolor(red)) ///
				(rcap upper lower incentive if cost == 3, lcolor(black) yaxis(2)) ///
				, ///
				xlabel(2(4)10) xscale(range(1 11) ) ///
				ytitle("P(participate)") ytitle("E(cost | participate)", axis(2)) xtitle("Incentive") ///
				ylabel(0.1(0.1)0.7) ///
				ylabel(1.7(0.2)2.1, axis(2)) ///
				yscale(range(0.2 2.1) axis(2)) ///
				legend(order(1 "Low cost" 2 "Medium cost" 3 "High cost" 7 "E(cost | participate)" ) col(1) pos(5) ring(0)) /// 
				aspect(0.8) scale(*1.1) ///
				bgcolor(white) graphregion(color(white)) 
			graph export "graphs/supplyCurvesMainECostPaper.pdf", replace
		restore	
		
		
		

	





}
	

	// Reservation prices
	if 1 {
		// All data
		if 1 {	
			
			cap drop resPricePred
			gen resPricePred = wtaRankMean
		
			capture drop resPriceH*
			su resPricePred, d
			gen resPriceH1 = resPricePred <= r(p50)
			gen resPriceH2 = resPricePred >  r(p50)
			gen resPriceH = . 
			forvalues i = 1 / 2 {
				replace resPriceH = `i' if resPriceH`i' == 1
			}
			
			capture: postclose supplyCurvesWTA2
			postfile supplyCurvesWTA2 mean sd incentive wta using "data/supplyCurvesWTA2.dta", replace
			
			capture drop weightsupplyCurvesWTA2
			gen weightsupplyCurvesWTA2 = .

			forvalues inc = 0 / 2 {
				forvalues q = 1 / 2 {
					su state 												if resPriceH == `q' & incentive == `inc' & explicit == 0
					replace weightsupplyCurvesWTA2 = 1 / r(mean)			if state == 1 & incentive == `inc' & resPriceH == `q'
					replace weightsupplyCurvesWTA2 = 1 / (1 - r(mean)) 		if state == 0 & incentive == `inc' & resPriceH == `q'
					reg bet [aw = weightsupplyCurvesWTA2] if resPriceH == `q'  & incentive == `inc' & explicit == 0
					post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (`q')
				}
			}

			replace resPriceH = resPriceH - 1
			
			local inc = 0
			reg resPriceH [aw = weightsupplyCurvesWTA2] if bet == 1 & incentive == `inc' & explicit == 0
			post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (3)
			local inc = 1
			reg resPriceH [aw = weightsupplyCurvesWTA2] if bet == 1 & incentive == `inc' & explicit == 0
			post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (3)
			local inc = 2
			reg resPriceH [aw = weightsupplyCurvesWTA2] if bet == 1 & incentive == `inc' & explicit == 0
			post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (3)
			
			
			postclose supplyCurvesWTA2
			
			
			preserve
				clear
				use "data/supplyCurvesWTA2.dta"
				gen upper = mean + 1.96*sd
				gen lower = mean - 1.96*sd
				
				replace incentive = 10 if incentive == 2
				replace incentive = 6 if incentive == 1
				replace incentive = 2 if incentive == 0
				
				tw 	(line mean incentive if wta == 1, lpattern(shortdash) 		lcolor(blue)	lwidth(0.55)) ///
					(line mean incentive if wta == 2, lpattern(solid) 	lcolor(red)		lwidth(0.55)) ///
					(line mean incentive if wta == 3, lpattern(solid) 	lcolor(black)	lwidth(1.35) yaxis(1)) ///
					(rcap upper lower incentive if wta == 1, lcolor(blue) ) ///
					(rcap upper lower incentive if wta == 2, lcolor(red)) ///
					(rcap upper lower incentive if wta == 3, lcolor(black) yaxis(1)) ///
					, ///
					legend(order(1 "Res. price < median" 2 "Res. price > median" 3 "P(Res. price > med. | particip.)") pos(4) ring(0) col(1)) /// 
					xlabel(2(4)10) xscale(range(1 11) ) ///
					ytitle("P(participate)") xtitle("Incentive") ///
					ylabel(0.2(0.1)0.6) ///
					aspect(0.8) scale(*1.09) ///
					bgcolor(white) graphregion(color(white)) 
				graph export "graphs/supplyCurvesWTAmainEcostPaper.pdf", replace
			restore	
			
			
			
			
		}
			

		// Fixed information treatment
		if 1 {	
			preserve
				cap drop resPricePred
				gen resPricePred = wtaRankMean
			
				capture drop resPriceH*
				su resPricePred, d
				gen resPriceH1 = resPricePred <= r(p50)
				gen resPriceH2 = resPricePred >  r(p50)
				gen resPriceH = . 
				forvalues i = 1 / 2 {
					replace resPriceH = `i' if resPriceH`i' == 1
				}
				
				capture: postclose supplyCurvesWTA2
				postfile supplyCurvesWTA2 mean sd incentive wta using "data/supplyCurvesWTA2.dta", replace
				
				capture drop weightsupplyCurvesWTA2
				gen weightsupplyCurvesWTA2 = .

				keep if explicit == 1
				
				forvalues inc = 0 / 2 {
					forvalues q = 1 / 2 {
						su state 												if resPriceH == `q' & incentive == `inc' 
						replace weightsupplyCurvesWTA2 = 1 / r(mean)			if state == 1 & incentive == `inc' & resPriceH == `q'
						replace weightsupplyCurvesWTA2 = 1 / (1 - r(mean)) 		if state == 0 & incentive == `inc' & resPriceH == `q'
						reg bet [aw = weightsupplyCurvesWTA2] if resPriceH == `q'  & incentive == `inc' 
						post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (`q')
					}
				}

				replace resPriceH = resPriceH - 1
				
				local inc = 0
				reg resPriceH [aw = weightsupplyCurvesWTA2] if bet == 1 & incentive == `inc' 
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (3)
				local inc = 1
				reg resPriceH [aw = weightsupplyCurvesWTA2] if bet == 1 & incentive == `inc' 
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (3)
				local inc = 2
				reg resPriceH [aw = weightsupplyCurvesWTA2] if bet == 1 & incentive == `inc' 
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (3)
				
				
				postclose supplyCurvesWTA2
				
			
				clear
				use "data/supplyCurvesWTA2.dta"
				gen upper = mean + 1.96*sd
				gen lower = mean - 1.96*sd
				
				replace incentive = 10 if incentive == 2
				replace incentive = 6 if incentive == 1
				replace incentive = 2 if incentive == 0
				
				tw 	(line mean incentive if wta == 1, lpattern(shortdash) 		lcolor(blue) lwidth(0.55)) ///
					(line mean incentive if wta == 2, lpattern(solid) 	lcolor(red)  lwidth(0.55)) ///
					(line mean incentive if wta == 3, lpattern(solid) 		lcolor(black)  lwidth(1.35)) ///
					(rcap upper lower incentive if wta == 1, lcolor(blue) ) ///
					(rcap upper lower incentive if wta == 2, lcolor(red) 	) ///
					(rcap upper lower incentive if wta == 3, lcolor(black) 	) ///
					, ///
					legend(order(1 "Res. price < median" 2 "Res. price > median" 3 "P(Res. pr. > med. | part.)") pos(4) ring(0) col(1)) /// 
					xlabel(2(4)10) xscale(range(1 11) ) ///
					ytitle("P(participate)") xtitle("Incentive") ///
					ylabel(0(0.2)0.8) ///
					aspect(0.8) scale(*1.1) ///
					bgcolor(white) graphregion(color(white)) 
				graph export "graphs/supplyCurvesWTAexplicitPaper.pdf", replace
			restore

			
		}
			
		
		
		
		
		
	}

	


}

******* Selection	  				
if 1 {
	// Reservation prices
		if 1 {	
			
			
			capture drop resPricePred
			gen resPricePred = wtaRankMean
		
			capture drop resPriceH*
			su resPricePred, d
			gen resPriceH1 = resPricePred <= r(p50)
			gen resPriceH2 = resPricePred >  r(p50)
			gen resPriceH = . 
			forvalues i = 1 / 2 {
				replace resPriceH = `i' if resPriceH`i' == 1
			}
			
			cap drop resPriceRank
			gen resPriceRank = resPriceH - 1
			
					
			capture: postclose supplyCurvesWTA2
			postfile supplyCurvesWTA2 mean sd incentive wta using "data/supplyCurvesWTA2.dta", replace
			
			capture drop weightProp3
			gen weightProp3 = .

			forvalues q = 1 / 3 {
				forvalues inc = 0 / 2 {
					su state 									if cost == `q' & incentive == `inc' & explicit == 0
					replace weightProp3 = 1 / r(mean)			if state == 1 & incentive == `inc' & cost == `q'
					replace weightProp3 = 1 / (1 - r(mean)) 	if state == 0 & incentive == `inc' & cost == `q'

					reg resPriceRank [aw = weightProp3] if bet == 1 & incentive == `inc' & explicit == 0 & cost == `q'
					post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (`q')
				}
			}
			
			postclose supplyCurvesWTA2
			
			preserve
				clear
				use "data/supplyCurvesWTA2.dta"
				gen upper = mean + 1.96*sd
				gen lower = mean - 1.96*sd
				
				replace incentive = 10 if incentive == 2
				replace incentive = 6 if incentive == 1
				replace incentive = 2 if incentive == 0
				
				tw 	(line mean incentive if wta == 1, lpattern(shortdash) 	lwidth(1) lcolor(black)) ///
					(line mean incentive if wta == 2, lpattern(longdash) 	lwidth(1) lcolor(black)) ///
					(line mean incentive if wta == 3, lpattern(solid) 	lwidth(1) lcolor(black)) ///
					, ///
					legend(order(1 "Low-cost tr." 2 "Medium-cost tr." 3 "High-cost tr." ) pos(4) ring(0) col(1)) /// 
					xlabel(2(4)10) xscale(range(1 11) ) ///
					ytitle("P(Res. price > median | participate)") xtitle("Incentive") ///
					ylabel(0.35(0.05)0.55) ///
					aspect(0.8) scale(*1.1) ///
					bgcolor(white) graphregion(color(white)) 
				graph export "graphs/selectionAndCostPaper.pdf", replace
			restore	
			
					
		}
			
		
	




}

******* Posteriors		  	
if 1 {
	// Experimental variation
	if 1 {	
				
		capture: postclose supplyCurvesWTA2
		postfile supplyCurvesWTA2 mean sd incentive wta using "data/supplyCurvesWTA2.dta", replace
		
		capture drop weightsupplyCurvesWTA2
		gen weightsupplyCurvesWTA2 = .

		forvalues inc = 0 / 2 {
			local incPlus = `inc' + 3
			forvalues q = 1 / 3 {
				su state 												if cost == `q' & incentive == `inc' & explicit == 0
				replace weightsupplyCurvesWTA2 = 1 / r(mean)			if state == 1 & incentive == `inc' & cost == `q'
				replace weightsupplyCurvesWTA2 = 1 / (1 - r(mean)) 		if state == 0 & incentive == `inc' & cost == `q'
				reg state [aw = weightsupplyCurvesWTA2] if cost == `q'  & incentive == `inc' & explicit == 0 & bet == 1
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (`q')
				reg state [aw = weightsupplyCurvesWTA2] if cost == `q'  & incentive == `inc' & explicit == 0 & bet == 0
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`incPlus') (`q')
			}
		}

		
		postclose supplyCurvesWTA2
		
		
		preserve
			clear
			use "data/supplyCurvesWTA2.dta"
			gen upper = mean + 1.96*sd
			gen lower = mean - 1.96*sd
			
			local color1 = "ebblue"
			local color2 = "dkorange"
			local color3 = "teal"
					
			label define costLabel 1 "Low" 2 "Medium" 3 "High" 
			label val wta costLabel
	
					
			tw 	(line mean wta if incentive == 0, lpattern(solid) 		lwidth(0.75)	lcolor(`color1') 	) ///
				(line mean wta if incentive == 1, lpattern(longdash) 	lwidth(0.75)	lcolor(`color2')	) ///
				(line mean wta if incentive == 2, lpattern(shortdash) 	lwidth(0.75)	lcolor(`color3')) ///
				(line mean wta if incentive == 3, lpattern(solid) 		lwidth(0.75)	lcolor(`color1') 	) ///
				(line mean wta if incentive == 4, lpattern(longdash) 	lwidth(0.75)	lcolor(`color2')	) ///
				(line mean wta if incentive == 5, lpattern(shortdash) 	lwidth(0.75)	lcolor(`color3')) ///
				(rcap upper lower wta if incentive == 0, lcolor(`color1') 	) ///
				(rcap upper lower wta if incentive == 1, lcolor(`color2')	) ///
				(rcap upper lower wta if incentive == 2, lcolor(`color3')) ///
				(rcap upper lower wta if incentive == 3, lcolor(`color1') 	) ///
				(rcap upper lower wta if incentive == 4, lcolor(`color2')	) ///
				(rcap upper lower wta if incentive == 5, lcolor(`color3')) ///
				, ///
				legend(order(1 "Incentive 2 " 2 "Incentive 6" 3 "Incentive 10") pos(9) ring(0) col(1)) /// 
				xlabel(1(1)3, val) xscale(range(0.5 3.5) ) ///
				ytitle("Posterior P(s = G | action)") xtitle("Task Difficulty Level") ///
				ylabel(0.1(0.2)1) yscale(range(0 1)) ///
				aspect(0.8) scale(*1.1) ///
				bgcolor(white) graphregion(color(white)) 
				graph play acceptRejectLabelsTreatments
			graph export "graphs/posteriorObj.pdf", replace

			
		restore	

	}
		
	// WTA by incentive
	if 1 {	
		capture drop resPriceRank
		gen resPriceRank = wtaRankM
		local bw = 0.15	
		tw 	(lpoly state resPriceRank if bet == 1 & incentive == 2, bw(`bw')	lpattern(solid) 		lwidth(0.75)	lcolor(navy) 	)		///
			(lpoly state resPriceRank if bet == 1 & incentive == 1, bw(`bw')	lpattern(longdash) 		lwidth(0.75)	lcolor(maroon)	)		///
			(lpoly state resPriceRank if bet == 1 & incentive == 0, bw(`bw')	lpattern(shortdash) 	lwidth(0.75)	lcolor(dkgreen)	)		///
			(lpoly state resPriceRank if bet == 0 & incentive == 2, bw(`bw')	lpattern(solid) 		lwidth(0.75)	lcolor(navy) 	)		///
			(lpoly state resPriceRank if bet == 0 & incentive == 1, bw(`bw')	lpattern(longdash) 		lwidth(0.75)	lcolor(maroon)	)		///
			(lpoly state resPriceRank if bet == 0 & incentive == 0, bw(`bw')	lpattern(shortdash) 	lwidth(0.75)	lcolor(dkgreen)	)		///
			, ///
			legend(order(3 "Incentive 2" 2 "Incentive 6" 1 "Incentive 10") pos(9) ring(0) col(1)) /// 
			xlabel(0(0.2)1) xscale(range(-0.2 1.2) ) ///
			ytitle("Posterior P(s = G | action)") xtitle("Reservation Price Percentile") ///
			ylabel(0.1(0.2)1) ///
			aspect(0.8) scale(*1.1) ///
			bgcolor(white) graphregion(color(white)) 
			graph play acceptRejectLabels
			graph export "graphs/posteriorObjWTAinc.pdf", replace

			
	}
	
}
	
******* State-dependent participation by information cost	
if 1 {	
		capture: postclose supplyCurves
		postfile supplyCurves mean sd incentive cost using "data/supplyCurves.dta", replace
		
		capture drop weightSupplyCurves
		gen weightSupplyCurves = .

		su treatment
		local numTreatments = r(max)
		forvalues t = 1 / `numTreatments' {
			su state if treatment == `t' & session >= 5
			replace weightSupplyCurves = 1 / r(mean)			if state == 1 & treatment == `t'
			replace weightSupplyCurves = 1 / (1 - r(mean)) 		if state == 0 & treatment == `t'
		}
		
		egen incNum = group(incentive)
		replace incentive = incNum - 1
		
		local stateCond = 0
		
		reg bet [aw = weightSupplyCurves] if incentive == 0 & cost == 1 & session >= 5 & state == `stateCond'
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (0)
		reg bet [aw = weightSupplyCurves] if incentive == 1  & cost == 1 & session >= 5 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (0)
		reg bet [aw = weightSupplyCurves] if incentive == 2  & cost == 1 & session >= 5 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (0)
		
		reg bet [aw = weight] if incentive == 0 & cost == 2 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (1)
		reg bet [aw = weight] if incentive == 1  & cost == 2 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (1)
		reg bet [aw = weight] if incentive == 2  & cost == 2 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (1)
		reg bet [aw = weight] if incentive == 0 & cost == 3  & state == `stateCond'
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (2)
		reg bet [aw = weight] if incentive == 1  & cost == 3 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (2)
		reg bet [aw = weight] if incentive == 2  & cost == 3 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (2)

		
		postclose supplyCurves
		
		
		preserve
			clear
			use "data/supplyCurves.dta"
			gen upper = mean + 1.96*sd
			gen lower = mean - 1.96*sd
			
			tw 	(line mean incentive if cost == 0, lpattern(shortdash) lcolor(blue)		lwidth(0.55)) ///
				(line mean incentive if cost == 1, lpattern(longdash) lcolor(dkgreen)	lwidth(0.55)) ///
				(line mean incentive if cost == 2, lpattern(solid) lcolor(red)	lwidth(0.55)) /// 
				(rcap upper lower incentive if cost == 0, lcolor(blue)) ///
				(rcap upper lower incentive if cost == 1, lcolor(dkgreen)) ///
				(rcap upper lower incentive if cost == 2, lcolor(red)) ///
				, ///
				xlabel(2(4)10) xscale(range(1 11) ) ///
				ytitle("P(participate)") xtitle("Incentive") ///
				ylabel(0(0.1)1) ///
				legend(order(1 "Low cost" 2 "Medium cost" 3 "High cost")  col(3) pos(6) ring(1)) /// 
				aspect(0.8) scale(*1.1) ///
				bgcolor(white) graphregion(color(white)) 
		restore	
		
		
		// false neg
	
		capture: postclose supplyCurves
		postfile supplyCurves mean sd incentive cost using "data/supplyCurves.dta", replace
		
		capture drop weightSupplyCurves
		gen weightSupplyCurves = .

		su treatment
		local numTreatments = r(max)
		forvalues t = 1 / `numTreatments' {
			su state if treatment == `t' & session >= 5
			replace weightSupplyCurves = 1 / r(mean)			if state == 1 & treatment == `t'
			replace weightSupplyCurves = 1 / (1 - r(mean)) 		if state == 0 & treatment == `t'
		}
		
		
		local stateCond = 1
		
		reg bet [aw = weightSupplyCurves] if incentive == 0 & cost == 1 & session >= 5 & state == `stateCond'
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (0)
		reg bet [aw = weightSupplyCurves] if incentive == 1  & cost == 1 & session >= 5 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (0)
		reg bet [aw = weightSupplyCurves] if incentive == 2  & cost == 1 & session >= 5 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (0)
		
		reg bet [aw = weight] if incentive == 0 & cost == 2 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (1)
		reg bet [aw = weight] if incentive == 1  & cost == 2 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (1)
		reg bet [aw = weight] if incentive == 2  & cost == 2 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (1)
		reg bet [aw = weight] if incentive == 0 & cost == 3  & state == `stateCond'
		post supplyCurves (_b[_cons]) (_se[_cons]) (2) (2)
		reg bet [aw = weight] if incentive == 1  & cost == 3 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (6) (2)
		reg bet [aw = weight] if incentive == 2  & cost == 3 & state == `stateCond' 
		post supplyCurves (_b[_cons]) (_se[_cons]) (10) (2)

		
		
		postclose supplyCurves
		
		
		preserve
			clear
			use "data/supplyCurves.dta"
			gen upper = mean + 1.96*sd
			gen lower = mean - 1.96*sd
			
			graph addplot ///
			 	(line mean incentive if cost == 0, lpattern(shortdash) lcolor(blue)		lwidth(0.55)) ///
				(line mean incentive if cost == 1, lpattern(longdash) lcolor(dkgreen)	lwidth(0.55)) ///
				(line mean incentive if cost == 2, lpattern(solid) lcolor(red)	lwidth(0.55)) /// 
				(rcap upper lower incentive if cost == 0, lcolor(blue)) ///
				(rcap upper lower incentive if cost == 1, lcolor(dkgreen)) ///
				(rcap upper lower incentive if cost == 2, lcolor(red)) ///
				, ///
				xlabel(2(4)10) xscale(range(1 11) ) ///
				ytitle("P(participate)") xtitle("Incentive") ///
				ylabel(1(0.1)0) ///
				legend(order(1 "Low cost" 2 "Medium cost" 3 "High cost" ) col(3) pos(6) ring(1)) /// 
				aspect(0.8) scale(*1.1) ///
				bgcolor(white) graphregion(color(white)) 
				graph play statesExperimentalCost
				graph export "graphs/falsePosNegExpCost.pdf", replace
	
		restore	
		
		

		
	}
		
******* State-dependent participation by information cost (WTA)
if 1 {	
		
		cap drop resPricePred
		gen resPricePred = wtaRankMean
	
		capture drop resPriceH*
		su resPricePred, d
		gen resPriceH1 = resPricePred <= r(p50)
		gen resPriceH2 = resPricePred >  r(p50)
		gen resPriceH = . 
		forvalues i = 1 / 2 {
			replace resPriceH = `i' if resPriceH`i' == 1
		}
		
		capture: postclose supplyCurvesWTA2
		postfile supplyCurvesWTA2 mean sd incentive wta using "data/supplyCurvesWTA2.dta", replace
		
		capture drop weightsupplyCurvesWTA2
		gen weightsupplyCurvesWTA2 = .

		forvalues inc = 0 / 2 {
			forvalues q = 1 / 2 {
				su state 												if resPriceH == `q' & incentive == `inc' & explicit == 0
				replace weightsupplyCurvesWTA2 = 1 / r(mean)			if state == 1 & incentive == `inc' & resPriceH == `q'
				replace weightsupplyCurvesWTA2 = 1 / (1 - r(mean)) 		if state == 0 & incentive == `inc' & resPriceH == `q'
				reg bet [aw = weightsupplyCurvesWTA2] if state == 1 & resPriceH == `q'  & incentive == `inc' & explicit == 0
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (`q')
			}
		}

		
		postclose supplyCurvesWTA2
		
		preserve
			clear
			use "data/supplyCurvesWTA2.dta"
			gen upper = mean + 1.96*sd
			gen lower = mean - 1.96*sd
			
			replace incentive = 10 if incentive == 2
			replace incentive = 6 if incentive == 1
			replace incentive = 2 if incentive == 0
			
			tw 	(line mean incentive if wta == 1, lpattern(shortdash) 	lcolor(blue)	lwidth(0.75)) ///
				(line mean incentive if wta == 2, lpattern(solid) 		lcolor(red)		lwidth(0.75)) ///
				(rcap upper lower incentive if wta == 1, lcolor(blue) ) ///
				(rcap upper lower incentive if wta == 2, lcolor(red)) ///
				, ///
				legend(order(1 "WTA < median" 2 "WTA > median") pos(11) ring(0) col(1)) /// 
				xlabel(2(4)10) xscale(range(1 11) ) ///
				ytitle("P(participate)") xtitle("Incentive") ///
				ylabel(0(0.2)1) ///
				aspect(0.8) scale(*1.1) ///
				bgcolor(white) graphregion(color(white)) 
		restore	

		capture: postclose supplyCurvesWTA2
		postfile supplyCurvesWTA2 mean sd incentive wta using "data/supplyCurvesWTA2.dta", replace
		
		capture drop weightsupplyCurvesWTA2
		gen weightsupplyCurvesWTA2 = .

		forvalues inc = 0 / 2 {
			forvalues q = 1 / 2 {
				su state 												if resPriceH == `q' & incentive == `inc' & explicit == 0
				replace weightsupplyCurvesWTA2 = 1 / r(mean)			if state == 1 & incentive == `inc' & resPriceH == `q'
				replace weightsupplyCurvesWTA2 = 1 / (1 - r(mean)) 		if state == 0 & incentive == `inc' & resPriceH == `q'
				reg bet [aw = weightsupplyCurvesWTA2] if state == 0 & resPriceH == `q'  & incentive == `inc' & explicit == 0
				post supplyCurvesWTA2 (_b[_cons]) (_se[_cons]) (`inc') (`q')
			}
		}
		
		postclose supplyCurvesWTA2
		

		preserve
			clear
			use "data/supplyCurvesWTA2.dta"
			gen upper = mean + 1.96*sd
			gen lower = mean - 1.96*sd
			
			replace incentive = 10 if incentive == 2
			replace incentive = 6 if incentive == 1
			replace incentive = 2 if incentive == 0
			
			addplot: 	(line mean incentive if wta == 1, 	lpattern(shortdash) 	lcolor(blue)	lwidth(0.75)) ///
				(line mean incentive if wta == 2, 			lpattern(solid) 		lcolor(red)		lwidth(0.75)) ///
				(rcap upper lower incentive if wta == 1, lcolor(blue) ) ///
				(rcap upper lower incentive if wta == 2, lcolor(red)) ///
				, ///
				legend(order(1 "WTA < median" 2 "WTA > median") pos(11) ring(0) col(1)) /// 
				xlabel(2(4)10) xscale(range(1 11) ) ///
				ytitle("P(participate)") xtitle("Incentive") ///
				ylabel(0(0.2)1) ///
				aspect(0.8) scale(*1.1) ///
				bgcolor(white) graphregion(color(white)) 
			graph play statesWTA
			graph export "graphs/falsePosNegWTA.pdf", replace
		restore	
		
	}
			
******* FOSD graphs							
if 1 {

	cap gen incIndex = incentive + 1
	
	preserve
		keep if bet == 1 & explicit == 0
		
		cumul thresCost [aw = weight] if incIndex == 1, gen(c1)
		cumul thresCost [aw = weight] if incIndex == 2, gen(c2)
		cumul thresCost [aw = weight] if incIndex == 3, gen(c3)
		
		sort c1 c2 c3 thresCost
		
		tw 	(line c1 thresCost, lwidth(0.5) lpattern(solid)) /// 
		 	(line c2 thresCost, lwidth(0.5) lpattern(longdash)) /// 
			(line c3 thresCost, lwidth(0.5) lpattern(shortdash)) /// 
			, /// 
			legend(order(- "Incentive" 1 "{c 0128}2" 2 "{c 0128}6" 3 "{c 0128}10") ring(0) col(1) pos(11)) ///
			xtitle("c") /// 
			ytitle("P(Cost index {&le} c | participate)") ///
			xlabel(1(1)3) ///
			xscale(range(0.75 3.25)) ///
			scale(*1.3) aspect(0.85) ///
			bgcolor(white) graphregion(color(white)) 
			graph export "graphs/fosdInduced.pdf", replace
	restore
	
	
	preserve
		keep if bet == 1 & explicit == 0
		
		cumul wtaRankMean [aw = weight] if incIndex == 1, gen(c1)
		cumul wtaRankMean [aw = weight] if incIndex == 2, gen(c2)
		cumul wtaRankMean [aw = weight] if incIndex == 3, gen(c3)
		
		sort c1 c2 c3 thresCost
		
		tw 	(line c1 wtaRankMean, lwidth(0.5) lpattern(solid)) /// 
		 	(line c2 wtaRankMean, lwidth(0.5) lpattern(longdash)) /// 
			(line c3 wtaRankMean, lwidth(0.5) lpattern(shortdash)) /// 
			, /// 
			legend(order(- "Incentive" 1 "{c 0128}2" 2 "{c 0128}6" 3 "{c 0128}10") ring(0) col(1) pos(11)) ///
			xtitle("r") /// 
			ytitle("P(Rank WTA {&le} r | participate)") ///
			xlabel(0(0.2)1) ///
			xscale(range(-0.1 1.1)) ///
			scale(*1.3) aspect(0.9) ///
			bgcolor(white) graphregion(color(white)) 
			graph export "graphs/fosdMeasured.pdf", replace
	restore
		
	preserve
		keep if bet == 1 & explicit == 1
		
		cumul wtaRankMean [aw = weight] if incIndex == 1, gen(c1)
		cumul wtaRankMean [aw = weight] if incIndex == 2, gen(c2)
		cumul wtaRankMean [aw = weight] if incIndex == 3, gen(c3)
		
		sort c1 c2 c3 thresCost
		
		tw 	(line c1 wtaRankMean, lwidth(0.5) lpattern(solid)) /// 
		 	(line c2 wtaRankMean, lwidth(0.5) lpattern(longdash)) /// 
			(line c3 wtaRankMean, lwidth(0.5) lpattern(shortdash)) /// 
			, /// 
			legend(order(- "Incentive" 1 "{c 0128}2" 2 "{c 0128}6" 3 "{c 0128}10") ring(0) col(1) pos(11)) ///
			xtitle("r") /// 
			ytitle("P(Rank WTA {&le} r | participate)") ///
			xlabel(0(0.2)1) ///
			xscale(range(-0.1 1.1)) ///
			scale(*1.3) aspect(0.9) ///
			bgcolor(white) graphregion(color(white)) 
			graph export "graphs/fosdExplicit.pdf", replace
	restore


	preserve
		keep if bet == 1 & explicit == 0 & cost == 1
		
		cumul wtaRankMean [aw = weight] if incIndex == 1, gen(c1)
		cumul wtaRankMean [aw = weight] if incIndex == 2, gen(c2)
		cumul wtaRankMean [aw = weight] if incIndex == 3, gen(c3)
		
		sort c1 c2 c3 thresCost
		
		tw 	(line c1 wtaRankMean, lwidth(0.5) lpattern(solid)) /// 
		 	(line c2 wtaRankMean, lwidth(0.5) lpattern(longdash)) /// 
			(line c3 wtaRankMean, lwidth(0.5) lpattern(shortdash)) /// 
			, /// 
			legend(order(- "Incentive" 1 "{c 0128}2" 2 "{c 0128}6" 3 "{c 0128}10") ring(0) col(1) pos(11)) ///
			xtitle("r") /// 
			ytitle("P(Rank WTA {&le} r | participate)") ///
			xlabel(0(0.2)1) ///
			xscale(range(-0.1 1.1)) ///
			scale(*1.3) aspect(0.9) ///
			bgcolor(white) graphregion(color(white)) 
			graph export "graphs/fosdMeasured1.pdf", replace
	restore
	
	preserve
		keep if bet == 1 & explicit == 0 & cost == 2
		
		cumul wtaRankMean [aw = weight] if incIndex == 1, gen(c1)
		cumul wtaRankMean [aw = weight] if incIndex == 2, gen(c2)
		cumul wtaRankMean [aw = weight] if incIndex == 3, gen(c3)
		
		sort c1 c2 c3 thresCost
		
		tw 	(line c1 wtaRankMean, lwidth(0.5) lpattern(solid)) /// 
		 	(line c2 wtaRankMean, lwidth(0.5) lpattern(longdash)) /// 
			(line c3 wtaRankMean, lwidth(0.5) lpattern(shortdash)) /// 
			, /// 
			legend(order(- "Incentive" 1 "{c 0128}2" 2 "{c 0128}6" 3 "{c 0128}10") ring(0) col(1) pos(11)) ///
			xtitle("r") /// 
			ytitle("P(Rank WTA {&le} r | participate)") ///
			xlabel(0(0.2)1) ///
			xscale(range(-0.1 1.1)) ///
			scale(*1.3) aspect(0.9) ///
			bgcolor(white) graphregion(color(white)) 
			graph export "graphs/fosdMeasured2.pdf", replace
	restore
	
	
	preserve
		keep if bet == 1 & explicit == 0 & cost == 3
		
		cumul wtaRankMean [aw = weight] if incIndex == 1, gen(c1)
		cumul wtaRankMean [aw = weight] if incIndex == 2, gen(c2)
		cumul wtaRankMean [aw = weight] if incIndex == 3, gen(c3)
		
		sort c1 c2 c3 thresCost
		
		tw 	(line c1 wtaRankMean, lwidth(0.5) lpattern(solid)) /// 
		 	(line c2 wtaRankMean, lwidth(0.5) lpattern(longdash)) /// 
			(line c3 wtaRankMean, lwidth(0.5) lpattern(shortdash)) /// 
			, /// 
			legend(order(- "Incentive" 1 "{c 0128}2" 2 "{c 0128}6" 3 "{c 0128}10") ring(0) col(1) pos(11)) ///
			xtitle("r") /// 
			ytitle("P(Rank WTA {&le} r | participate)") ///
			xlabel(0(0.2)1) ///
			xscale(range(-0.1 1.1)) ///
			scale(*1.3) aspect(0.9) ///
			bgcolor(white) graphregion(color(white)) 
			graph export "graphs/fosdMeasured3.pdf", replace
	restore
		
}

